package com.barradata.app0624.modules.splash

import com.barradata.BuildConfig
import com.barradata.R
import com.barradata.app0624.data.AppDataManager
import com.barradata.app0624.modules.privacy.PrivacyActivity
import com.barradata.app0624.modules.web.WebActivity
import com.barradata.common.base.BaseActivity
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.TimeUnit

/**
 * Author:    WuNan
 * Email:     wunan@barradata.com
 * Created:   2019/7/6 22:13
 **/
class SplashActivity : BaseActivity() {
    override fun getLayoutId() = R.layout.splash_activity

    override fun initView() {
        Observable.timer(1500, TimeUnit.MILLISECONDS, Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    // DEBUG 模式时持续显示隐私政策
                    if (BuildConfig.DEBUG) {
                        AppDataManager.hasOpened = false
                    }
                    if (AppDataManager.hasOpened) {
                        WebActivity.actionStart(this)
                    } else {
                        PrivacyActivity.actionStart(this)
                    }
                    finish()
                }.autoClean()
    }

}